// Copyright (c) 2024 刻BITTER
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.


#pragma once

#include <avr/interrupt.h>

#include "ioxx_common.hpp"
#include "ioxx_include_device.hpp"

namespace irqxx {

    class CriticalScope {
       private:
        uint8_t _old_sreg;

       public:
        CriticalScope() {
            _old_sreg = SREG;
            cli();
        }

        ~CriticalScope() {
            SREG = _old_sreg;
        }
    };


}  // namespace irqxx